#define FOR_TEST
#include <iostream>
#include "password_hash.hpp"

int main() 
{
    std::vector<uint8_t> salt, storedHash;

    // 第一次运行时，文件不存在，生成盐值和哈希值并存储
    if (!PasswordHash::readCredentialsFromFile(salt, storedHash)) {
        std::cout << "首次运行，生成盐值和哈希值...\n";

        // 生成盐值
        salt = PasswordHash::generateSalt();

        // 使用预设密码生成哈希值
        auto hash = PasswordHash::hashPassword(PREDEFINED_PASSWORD, salt);

        // 保存盐值和哈希值到文件
        PasswordHash::saveCredentialsToFile(salt, hash);

        std::cout << "盐值和哈希值已保存到文件中\n";
        
        // 重新读取并更新盐值和哈希值
        PasswordHash::readCredentialsFromFile(salt, storedHash);
    } else {
        std::cout << "文件已存在，开始密码验证...\n";
    }

    // 验证密码
    std::string inputPassword;
    std::cout << "请输入密码: ";
    std::cin >> inputPassword;

    if (PasswordHash::verifyPassword(inputPassword, salt, storedHash)) {
        std::cout << "密码验证成功！\n";
    } else {
        std::cout << "密码验证失败！\n";
    }

    return 0;
}
